<?php
include dirname(__FILE__) . '/../bootstrap.php';

use \api\request\DomainQueryRequest;
use \api\response\Response;
use \model\service\DomainService;

/**
 * api接口入口函数, 搜索条件 https://www.juming.com/gq/
 * @param $argc
 * @param $argv
 * @return int
 */
function main(/* int */$argc, /* array{string}*/$argv) {
    header("Content-Type: application/json");
    $request = new DomainQueryRequest();

    try {
        $params = $request->getJsonParams();
        $invalidParams = array();
        $validatedParams = $request->validateParams($params, $invalidParams);
        if (!empty($invalidParams)) {
            return Response::err("域名查询参数错误", $invalidParams, 400);
        }
        unset($request);
        $service = new DomainService();
        $ans = $service->query($validatedParams);
        return Response::succ("OK", $ans);

    } catch (Exception $e) {
        return Response::err($e->getMessage(), [], $e->getCode());
    }
}

main($argc, $argv);